﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AntiObesity.Base.Managers;

namespace AntiObesity.Services
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            lblError.Text = "";
            var user = UserManager.FindByName(txtUserName.Text);
            if (user == null)
            {
                lblError.Text = "Invalid username or password";
            }
            else
            {
                if (user.Password != txtPassword.Text)
                {
                    lblError.Text = "Invalid username or password";
                }
                else
                {
                    Session.SetCurrentUser(user);
                    Response.Redirect("UserHome.aspx");
                }
            }
        }
    }
}
